/*
 * Created on 07-feb-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.juanfrivaldes.cio2005.gestion;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * @author root
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class GestionPonenciasAction extends GestionAction {

	private static Log log = LogFactory.getLog(GestionPonenciasAction.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.juanfrivaldes.cio2005.web.BaseAction#protectedExecute(org.apache.struts.action.ActionMapping,
	 *      org.apache.struts.action.ActionForm,
	 *      javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse)
	 */
	protected ActionForward protectedExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		List ponencias;
		GestionPonenciasFiltradasForm ponenciasForm = (GestionPonenciasFiltradasForm) form;
		request.getSession(false).setAttribute("usuario",null);

		if (request.getParameter("usuario") != null) {
			request.getSession(false).setAttribute("usuario",request.getParameter("usuario"));
			ponencias = this.getCio2005().getPonenciasWithUsuario(
					request.getParameter("usuario"));
		} else {

			if (ponenciasForm == null || ponenciasForm.getCategoria() == null) {
				ponencias = this.getCio2005().getPonencias();
			} else {
				log.trace("Se piden ponencias para categoria "
						+ ponenciasForm.getCategoria());
				ponencias = this.getCio2005().getPonenciasByCategoria(
						ponenciasForm.getCategoria());
			}
		}
		if (ponencias != null) {
			log.trace("Recuperadas " + ponencias.size() + " ponencias");
			request.getSession(false).setAttribute("nPonencias", new Integer(ponencias.size()));
			request.getSession(false).setAttribute("ponencias", ponencias);
		} else {
			request.setAttribute("nPonencias", new Integer(0));
		}

		return mapping.findForward("success");
	}

}
